//------------------------------------------------------------------------------
// <copyright company="Telligent Systems">
//     Copyright (c) Telligent Systems Corporation.  All rights reserved.
// </copyright> 
//------------------------------------------------------------------------------

using System;
using System.Web.UI.WebControls;
using CommunityServer.Blogs.Controls;
using CommunityServer.Components;
using CommunityServer.ControlPanel.UI;
using CommunityServer.Controls;
using ResourceLinkButton = CommunityServer.ControlPanel.Controls.ResourceLinkButton;
using ResourceManager = CommunityServer.ControlPanel.Components.ResourceManager;

namespace CommunityServer.ControlPanel.Galleries.Options
{
	/// <summary>
	/// Summary description for PostOptionsPage.
	/// </summary>
	public class DefaultPostSettings : BaseGalleryPage
	{

		#region Child Controls

		protected StatusMessage Status;
		protected YesNoRadioButtonList ynEnableReplies;
        protected YesNoRadioButtonList ynEnableRatings;
        protected YesNoRadioButtonList ynEnableTrackbacks;
		protected YesNoRadioButtonList ynAggregatePost;
		protected YesNoRadioButtonList ynCommunity;
		protected YesNoRadioButtonList ynEnableOrderPrints;
		protected YesNoRadioButtonList ynSyndicateExcerpt;
        protected CommentModerationDropDownList ModerationDDL;
		protected FeedbackNotificationDropDownList NotificationType;
		protected ResourceLinkButton SaveButton;

		#endregion

        override protected void OnInit(EventArgs e)
        {
            this.Load += new System.EventHandler(this.Page_Load);
            this.SaveButton.Click += new EventHandler(SaveButton_Click);
            base.OnInit(e);
        }

        
        private void Page_Load(object sender, EventArgs e)
		{
  
			if(!IsPostBack)
            {
                ynEnableReplies.SelectedValue = CurrentGallery.EnableComments;
                ynEnableRatings.SelectedValue = CurrentGallery.EnableRatings;
                ynEnableTrackbacks.SelectedValue = CurrentGallery.EnableTrackbacks;
				ynEnableOrderPrints.SelectedValue = CurrentGallery.EnableOrderPrints;
				ynAggregatePost.SelectedValue = CurrentGallery.EnablePostAggregationDefault;
                ynCommunity.SelectedValue = CurrentGallery.EnableCommunityParticipationDefault;
                ynSyndicateExcerpt.SelectedValue = CurrentGallery.SyndicateExcerptDefault;

                ListItem li = ModerationDDL.Items.FindByValue(CurrentGallery.ModerationTypeDefault.ToString());
                if(li != null)
                    li.Selected = true;

				NotificationType.SelectedValue = CurrentGallery.FeedbackNotificationType;

            }
		}

        private void SaveButton_Click(object sender, EventArgs e)
        {
            if(Page.IsValid)
            {

                
				CurrentGallery.EnableCommentsDefault = ynEnableReplies.SelectedValue;
                CurrentGallery.EnableRatingsDefault = ynEnableRatings.SelectedValue;
                CurrentGallery.EnableTrackbacksDefault = ynEnableTrackbacks.SelectedValue;
				CurrentGallery.EnableOrderPrints = ynEnableOrderPrints.SelectedValue;
				CurrentGallery.EnablePostAggregationDefault = ynAggregatePost.SelectedValue;
                CurrentGallery.EnableCommunityParticipationDefault = ynCommunity.SelectedValue;
                CurrentGallery.SyndicateExcerptDefault = ynSyndicateExcerpt.SelectedValue;

                CurrentGallery.ModerationTypeDefault = (CommentModerationType) Enum.Parse(typeof(CommentModerationType),ModerationDDL.SelectedValue);
				CurrentGallery.FeedbackNotificationType = NotificationType.SelectedValue;

            	CommunityServer.Galleries.Galleries.Update(CurrentGallery);

				Status.Success = true;
				// Status.Text = "Your changes have been saved successfully";
				Status.Visible = true;

            }
        }



    }
}
